package io.liang.jsidekiq.web.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import io.liang.jsidekiq.web.entity.BasCaptcha;
import io.liang.jsidekiq.web.repository.BasCaptchaRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.List;

/**
 * Created by sumu on 2017/5/24.
 */
@Controller
public class TestController {

    @Autowired
    private BasCaptchaRepository captchaRepository;

    @RequestMapping("/hello")
    String home() {
        return "/member/member-list";
    }

    @RequestMapping("/hello/list")
    @ResponseBody
    JSONObject list(Integer pageNum) {
        PageRequest pageRequest = new PageRequest(1,20,null);
        JSONObject jsonObject = new JSONObject();
        System.out.println(captchaRepository.findAll());
        Page<BasCaptcha> page = captchaRepository.findAll(pageRequest);
        System.out.println(page.getContent());
        jsonObject.put("tableList", JSON.toJSONString(page.getContent()));
        jsonObject.put("pages",page.getTotalPages());
        return jsonObject;
    }
}
